<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>调色板</title>
    <style>
        *{
            user-select: none;
        }
        .tsb{
            width: 300px;
            border:solid 1px rgb(190, 183, 183);
            margin: 100px auto;
            padding-bottom: 12px;
        }

        .show{
            height: 140px;
            background: rgb(138, 152, 192);
        }
        .colors, .result{
            padding-left: 20px;
        }
    </style>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component{
            // 1. state 属性
            state = {
                r: 0,
                g: 0,
                b: 0
            }
            render(){
                let {r,g,b} = this.state;
                return <div className="tsb">
                        <div className="show" style={{background: `rgb(${r},${g},${b})`}}></div>
                        <hr />
                        {/*2. 绑定 state 的值*/}
                        <div className="colors">
                            R: <input name="r" type="range" min="0" max="255" value={r} onChange={this.change}/> {r}<br/>
                            G: <input name="g" type="range" min="0" max="255" value={g} onChange={this.change}/> {g}<br/>
                            B: <input name="b" type="range" min="0" max="255" value={b} onChange={this.change}/> {b}<br/>
                        </div>
                        <hr/>
                        <div className="result">
                            <input type="text" value={`rgb(${r},${g},${b})`} readOnly/>
                        </div>
                    </div>
            }

            change = (e) => {
                //获取滑动后的值
                // console.log(e.target.value);
                let name = e.target.name;
                //3. 修改对应 state 属性的值
                this.setState({
                    [name]:e.target.value
                })
            }
        }

        ReactDOM.render(<App />, document.querySelector("#root"));

    </script>
</body>
</html>